#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
#include <sys/resource.h>
#define CHUNK_SIZE (1024 * 1024)
int main()
{
    char *some_memory;
    int megs_obtained = 0;
    struct rlimit rlt;
    rlim_t j, k = RLIM_INFINITY;
    getrlimit(RLIMIT_AS, &rlt);
    if (rlt.rlim_cur == RLIM_INFINITY)
    {
        printf("no limit on virtual memory!\n");
        exit(0);
    }
    while (1)
    {
        some_memory = (char *)malloc(CHUNK_SIZE);
        if (some_memory == NULL)
        {
            perror("no morememory!\n");
            exit(1);
        }
        megs_obtained++;
        printf("Now allocated %d Megabytes!\n", megs_obtained);
    }
    return 0;
}